package com.itheima.zy02;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Teacher> ts = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            //o1表示现在已经存入的那个元素
            //o2表示已经存入到集合中的元素
            public int compare(Teacher o1, Teacher o2) {
                int i = o1.getAge() - o2.getAge();
                i = i == 0 ? o1.getName().compareTo(o2.getName()) : i;
                return i;
            }
        });
        Teacher teacher = new Teacher("张三", 95);
        Teacher teacher1 = new Teacher("李四", 93);
        Teacher teacher2 = new Teacher("王五", 20);
        Teacher teacher3 = new Teacher("逗逗", 65);

        ts.add(teacher);
        ts.add(teacher1);
        ts.add(teacher2);
        ts.add(teacher3);

    }
}
